#include <cstdio>

const int N = 1e6 + 5;

int n, ans[N], stk[N], top, w[N];
int e_cnt, heads[N];

struct Edge {
  int v, nxt;
} e[N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void solve(int x) {
  int l = 0, r = top + 1, mid, tmp, ttop;
  while (l < r) {
    mid = (l + r) >> 1;
    if (stk[mid] < w[x]) r = mid;
    else
      l = mid + 1;
  }
  tmp = stk[r], stk[r] = w[x];
  ttop = top, top = r;
  ans[x] = top + 1;
  for (int i = heads[x]; i; i = e[i].nxt) solve(e[i].v);
  stk[r] = tmp, top = ttop;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("suffix.in", "r", stdin);
  freopen("suffix.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 2, fa; i <= n; ++i) {
    scanf("%d", &fa);
    add(fa, i);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  solve(1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}